<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.min.js"></script>
    <style>
        button{
            width: 100px;
            height: 100px;
            background: red;
            padding: 5px;
        }
    </style>
</head>
<body>
    <button>get请求</button>
    <button>post请求</button>
    <button>put请求</button>
    <button>delete请求</button>
</body>
</html>
<script>
    const btn = document.querySelectorAll('button')

    //设置默认 配置
    // axios.defaults.method = 'get'



    btn[0].addEventListener('click',() => {
        axios({
            method:'GET',
            url:"http://localhost:3000/posts/1",
        }).then(res => {
            console.log(res);
        })
    }),
    btn[1].addEventListener('click',() => {
        axios({
            method:'post',
            url:"http://localhost:3000/posts",
            data:{
                "title":"我爱 祖国",
                "author":"ming"
            }
        }).then(res => {
            console.log(res);
        })
    }),
    btn[2].addEventListener('click',() => {
        axios({
            method:'put',
            url:"http://localhost:3000/posts/3",
            data:{
                "title":"我爱 祖国",
                "author":"hong"
            }
        }).then(res => {
            console.log(res);
        })
    })
    btn[3].addEventListener('click',() => {
        axios({
            method:'delete',
            url:"http://localhost:3000/posts/5"
        }).then(res => {
            console.log(res);
        })
    })
</script>